<template>
  <div class="con">
    <div class="contbox6_10">
      <p class="titlelist6_10">
        机构管理
        <span style="color: #999">&nbsp;&nbsp;/&nbsp;&nbsp;</span>机构业务 /
        开通银行
      </p>
      <div class="content">
        <div >
          <div class="jibenInfo">业务信息</div>
          <el-form ref="forms" :model="forms" label-width="140px">
            <el-form-item class="list" label="开启状态">
              <el-select v-model="submitList.status" placeholder>
                <el-option label="开启" value="0"></el-option>
                <el-option label="关闭" value="1"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item class="list" label="银行卡类型">
              <el-select
                v-model="submitList.cardType"
                placeholder="请选择银行卡类型"
                @change="list"
              >
                <el-option label="请选择" value=""></el-option>
                <el-option label="信用卡" value="1"></el-option>
                <el-option label="储蓄卡" value="2"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item class="list" label="支持银行">
              <!-- <el-input v-model="submitList.bankName"></el-input> -->
              <el-select
                @change="bankList"
                v-model="submitList.bankName"
                placeholder
              >
                <el-option
                  v-for="item in options"
                  :key="item.bankCode"
                  :label="item.bankName"
                  :value="[item.bankCode, item.bankName]"
                >
                </el-option>
              </el-select>
            </el-form-item>

            <el-form-item
            class="list"
              label="机构d0交易费率"
              v-if="$route.query.agtType == 0"
              >
              <el-input v-model="submitList.d0TradeRate"></el-input>%
            </el-form-item>
            <el-form-item class="list" label="机构d0手续费" v-if="$route.query.agtType == 0"
              >
              <el-input v-model="submitList.d0DrawFee"></el-input>元
            </el-form-item>
            <el-form-item class="list" label="商户d0交易费率"
              >
              <el-input v-model="submitList.memberTradeRate"></el-input>元
            </el-form-item>
            <el-form-item class="list" label="商户d0手续费"
              >
              <el-input v-model="submitList.memberDrawFee"></el-input>元
            </el-form-item>

            <el-form-item class="list" label="单笔最低限额"
              >
              <el-input v-model="submitList.singleLowest"></el-input>元
            </el-form-item>
            <el-form-item class="list" label="单笔最高限额"
              >
              <el-input v-model="submitList.singleLimit"></el-input>元
            </el-form-item>
            <el-form-item class="list" label="单卡单日限额"
              >
              <el-input v-model="submitList.dayLimit"></el-input>元
            </el-form-item>
            <el-form-item class="list" label="单卡单月限额"
              >
              <el-input v-model="submitList.monthLimit"></el-input>元
            </el-form-item>
            <!-- <el-form-item label="交易笔数限制 "
          >&nbsp;&nbsp;&nbsp;&nbsp;
          <el-input v-model="submitList.mechanismNo"></el-input>元
        </el-form-item> -->
            <!-- <el-form-item label="预设生效时间 "
          >&nbsp;&nbsp;&nbsp;&nbsp;

          <el-date-picker
            class="selectTimer"
            value-format="yyyy-MM-dd HH:mm:ss"
            v-model="value1"
            type="datetime"
            placeholder="选择日期时间"
          >
          </el-date-picker>
        </el-form-item> -->
        <el-col>
            <el-form-item>
              <el-button type="primary" @click="submit">保存</el-button>
              <el-button @click="back">取消</el-button>
            </el-form-item></el-col>
          </el-form>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import axios from "axios";
export default {
  data() {
    return {
      formsDisplay: true,
      form: {
        region: ""
      },
      forms: {
        mechanismNo: ""
      },
      formes: {
        region: ""
      },
      options: null,
      submitList: {
        oemUid: "",
        id: "",
        channelCode: "", //通道编号
        busCode: "", //支付业务编码
        bankCode: "", //银行编号
        bankName: "", //银行名称
        cardType: "", //卡类型
        d0DrawFee: "", //平台D0提现费
        d0TradeRate: "", //平台d0交易费率
        singleLowest: "", //单笔最低限额
        memberDrawFee: "",
        memberTradeRate: "",
        singleLimit: "", //单笔最高限额
        dayLimit: "", //日交易限额
        monthLimit: "", //月交易限额
        status: "", //业务状态
        officeUid: "",
        agtType: "1",
        temp: ""
      },
      //生效时间
      pickerOptions: {
        shortcuts: [
          {
            text: "今天",
            onClick(picker) {
              picker.$emit("pick", new Date());
            }
          },
          {
            text: "昨天",
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24);
              picker.$emit("pick", date);
            }
          },
          {
            text: "一周前",
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", date);
            }
          }
        ]
      }
    };
  },
  created() {
    this.submitList.channelCode = this.$route.query.channelCode;
    this.submitList.agtType = this.$route.query.agtType;
    this.submitList.oemUid = this.$route.query.oemUid;
    this.submitList.officeUid = this.$route.query.officeUid;
    // axios
    //   .post("/api/channel/saveBank", {})
    //   .then((res) => {
    //     console.log(res);
    //   })
    //   .catch((err) => {
    //     console.log(err);
    //   });
    //获取支持银行
    axios
      .get("/bank/queryBank")
      .then(res => {
        // alert("获取支持银行成功")
        console.log(res);
        this.options = res.data.data;
      })
      .catch(err => {
        console.log(err);
      });
    var id = this.$route.query.id;
    // alert(id)

    let boos = this.$route.query.disb;
    // alert(id)
    if (boos == "y") {
      console.log("下面是回显数据");
      // alert(this.submitList.agtType)
      axios
        .post("/api/bus/updateById", {
          id: Number(id),
          agtType: this.submitList.agtType
        })
        .then(res => {
          console.log("回显成功11111111111111111111111");
          // alert("成功")
          console.log(res);
          // alert("数据成功")
          this.submitList = res.data.data;
          // this.temp = res.data.data.memberDrawFee
          // this.submitList.memberDrawFee=this.temp
        })
        .catch(err => {
          console.log(err);
        });
    }
  },
  methods: {
    // 开通业务选择
    list(event, item) {
      console.log(event);
      if (event != 0) {
        this.formsDisplay = false;
      }
    },
    submit() {
      console.log(this.submitList.channelCode);
      this.submitList.agtType = this.$route.query.agtType;
      // return
      //获取通道编号
      if (
        this.submitList.channelCode != "" &&
        this.bankType() &&
        this.openStatus() &&
        this.bankSupport() &&
        this.membera() &&
        this.memeberb() &&
        this.minLimit() &&
        this.maxLimit &&
        this.maxLimit() &&
        this.dayCard() &&
        this.mounthCard()
      ) {
        axios
          .post("/api/bus/saveBank", this.submitList)
          .then(res => {
            // alert("创建成");
            console.log(res);
            this.$router.go(-1);
          })
          .catch(err => {
            console.log(err);
          });
      } else {
        alert("输入信息有误");
      }
    },
    bankList(val) {
      console.log(val);
      this.submitList.bankCode = val[0];
      // alert(this.submitList.bankCode)
      this.submitList.bankName = val[1];
    },
    //检测开启状态
    openStatus() {
      if (this.status != "") {
        // alert("正确")
        return true;
      } else {
        // alert("选择开启状态")
        return false;
      }
    },
    //判断银行卡类型是否选择
    bankType() {
      if (this.cardType != "") {
        return true;
      } else {
        // alert("选择银行卡类型")
        return false;
      }
    },
    //判断支持银行
    bankSupport() {
      if (this.bankName != "") {
        return true;
      } else {
        // alert("选择支持银行")
        return false;
      }
    },
    //判断机构d0交易费率
    mechanism1() {
      if (this.d0TradeRate != "") {
        return true;
      } else {
        // alert("机构d0交易费率不能为空")
        return false;
      }
    },
    //机构d0手续费
    mechanism2() {
      if (this.d0DrawFee != "") {
        return true;
      } else {
        return false;
        // alert("是空的")
      }
    },
    //商户d0交易费
    membera() {
      if (this.memberTradeRate != "") {
        return true;
      } else {
        // alert("商户d0交易费率不能为空")
        return false;
      }
    },

    //商户d0手续费
    memeberb() {
      if (this.memberDrawFee != "") {
        return true;
      } else {
        // alert("商户d0手续费不能为空")
        return false;
      }
    },
    //单笔最低限额
    minLimit() {
      if (this.singleLowest != "") {
        return true;
      } else {
        // alert("单笔最低限额是空")
        return false;
      }
    },
    //单笔最高限额
    maxLimit() {
      if (this.singleLimit != "") {
        return true;
      } else {
        return false;
      }
    },
    //单日限额
    dayCard() {
      if (this.dayLimit != "") {
        return true;
      } else {
        return false;
      }
    },
    //单月限额
    mounthCard() {
      if (this.monthLimit != "") {
        return true;
      } else {
        return false;
      }
    },
    back() {
      this.$router.go(-1);
    }
  }
};
</script>
<style scoped>
.con {
  position: relative;
}
.contbox6_10 {
  width: 100%;
  /* min-height: 10px;
  margin-left: 2%;
  height: 85px; */
  overflow-x: auto;
  box-sizing: border-box;
  float: left;
}
.select {
  float: left;
  width: 100%;
  margin-left: 2%;
  margin-top: 20px;
}
.jibenInfo {
  width: calc(100% - 40px);
  margin: 20px;
  height: 40px;
  line-height: 40px;
  padding-left: 20px;
  background: #f9fafc;
  float: left;
}
.forms {
  float: left;
  width: 100%;
  margin-left: 2%;
  margin-top: 20px;
}
/deep/ .el-input {
  width: 266px;
}
/deep/ .el-input__inner {
  width: 266px;
}

.formsTwo {
  float: left;
  width: 100%;
  margin-left: 2%;
  margin-top: 20px;
}
p {
  font-size: 16px;
}
.borders {
  border-bottom: 2px solid #ccc;
  margin-bottom: 15px;
  margin-top: 20px;
}
.el-date-picker__editor-wrap .el-input {
  width: 90px !important;
}
/deep/ .selectTimer .el-input {
  width: 150px !important;
}
.list{
  width:570px
}
</style>
